package com.aptoto.thrift.offcial.separation;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TField;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolUtil;
import org.apache.thrift.protocol.TType;
import org.apache.thrift.scheme.SchemeFactory;
import org.apache.thrift.scheme.StandardScheme;

public class MStandardSchemeFactory implements SchemeFactory {
	@Override
	public MStandardScheme getScheme() {
		return new MStandardScheme();
	}
	
	public static class MStandardScheme extends StandardScheme<M> {
		public void read(TProtocol iprot, M struct) throws TException {
			TField schemeField;
			iprot.readStructBegin();
			while (true) {
				schemeField = iprot.readFieldBegin();
				if (schemeField.type == TType.STOP) {
					break;
				}
				switch (schemeField.id) {
				case 12: // AA
					if (schemeField.type == TType.BOOL) {
						struct.aa = iprot.readBool();
						struct.setAaIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				case 5: // BB
					if (schemeField.type == TType.BYTE) {
						struct.bb = iprot.readByte();
						struct.setBbIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				case 3: // CC
					if (schemeField.type == TType.I16) {
						struct.cc = iprot.readI16();
						struct.setCcIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				case 6: // DD
					if (schemeField.type == TType.I32) {
						struct.dd = iprot.readI32();
						struct.setDdIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				case 9: // EE
					if (schemeField.type == TType.I64) {
						struct.ee = iprot.readI64();
						struct.setEeIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				case 44: // FF
					if (schemeField.type == TType.DOUBLE) {
						struct.ff = iprot.readDouble();
						struct.setFfIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				case 32: // GG
					if (schemeField.type == TType.STRING) {
						struct.gg = iprot.readString();
						struct.setGgIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				case 1: // HH
					if (schemeField.type == TType.STRING) {
						struct.hh = iprot.readString();
						struct.setHhIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				case 2: // II
					if (schemeField.type == TType.I32) {
						struct.ii = iprot.readI32();
						struct.setIiIsSet(true);
					} else {
						TProtocolUtil.skip(iprot, schemeField.type);
					}
					break;
				default:
					TProtocolUtil.skip(iprot, schemeField.type);
				}
				iprot.readFieldEnd();
			}
			iprot.readStructEnd();

			// check for required fields of primitive type, which can't be
			// checked in the validate method
			struct.validate();
		}

		public void write(TProtocol oprot, M struct) throws TException {
			struct.validate();

			oprot.writeStructBegin(M.STRUCT_DESC);
			if (struct.hh != null) {
				oprot.writeFieldBegin(M.HH_FIELD_DESC);
				oprot.writeString(struct.hh);
				oprot.writeFieldEnd();
			}
			oprot.writeFieldBegin(M.II_FIELD_DESC);
			oprot.writeI32(struct.ii);
			oprot.writeFieldEnd();
			oprot.writeFieldBegin(M.CC_FIELD_DESC);
			oprot.writeI16(struct.cc);
			oprot.writeFieldEnd();
			oprot.writeFieldBegin(M.BB_FIELD_DESC);
			oprot.writeByte(struct.bb);
			oprot.writeFieldEnd();
			oprot.writeFieldBegin(M.DD_FIELD_DESC);
			oprot.writeI32(struct.dd);
			oprot.writeFieldEnd();
			oprot.writeFieldBegin(M.EE_FIELD_DESC);
			oprot.writeI64(struct.ee);
			oprot.writeFieldEnd();
			oprot.writeFieldBegin(M.AA_FIELD_DESC);
			oprot.writeBool(struct.aa);
			oprot.writeFieldEnd();
			if (struct.gg != null) {
				oprot.writeFieldBegin(M.GG_FIELD_DESC);
				oprot.writeString(struct.gg);
				oprot.writeFieldEnd();
			}
			oprot.writeFieldBegin(M.FF_FIELD_DESC);
			oprot.writeDouble(struct.ff);
			oprot.writeFieldEnd();
			oprot.writeFieldStop();
			oprot.writeStructEnd();
		}

	}
}
